﻿@model RoadFlow.Model.Menu
@using RoadFlow.Utility
<link href="~/RoadFlowResources/scripts/bigcolorpicker/css/jquery.bigcolorpicker.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="~/RoadFlowResources/scripts/bigcolorpicker/js/jquery.bigcolorpicker.js"></script>
<script type="text/javascript" src="~/RoadFlowResources/scripts/bigcolorpicker/js/syntaxHighlighter/shCore.js"></script>
<script type="text/javascript" src="~/RoadFlowResources/scripts/bigcolorpicker/js/syntaxHighlighter/shBrushJScript.js"></script>
<script type="text/javascript" src="~/RoadFlowResources/scripts/bigcolorpicker/js/syntaxHighlighter/shBrushJava.js"></script>
<link href="~/RoadFlowResources/scripts/bigcolorpicker/css/syntaxHighlighter/shCore.css" rel="stylesheet" type="text/css" />
<link href="~/RoadFlowResources/scripts/bigcolorpicker/css/syntaxHighlighter/shCoreDefault.css" rel="stylesheet" type="text/css" />
<link href="~/RoadFlowResources/scripts/bigcolorpicker/css/syntaxHighlighter/shThemeDefault.css" rel="stylesheet" type="text/css" />
<br />
<form method="post">
    @Html.AntiForgeryToken()
    <input type="hidden" name="Id" value="@Model.Id" />
    <input type="hidden" name="Sort" value="@Model.Sort" />
    <input type="hidden" name="ParentId" value="@Model.ParentId" />
    <table cellpadding="0" cellspacing="1" border="0" width="95%" class="formtable">
        <tr>
            <th style="width:80px;">应用名称：</th>
            <td><input type="text" id="Title" name="Title" class="mytext" value="@Model.Title" validate="empty" style="width:65%" /></td>
        </tr>
        <tr>
            <th style="width:80px;">关联程序：</th>
            <td>
                <select id="Type" onchange="loadApp(this.value);" style="width:130px;" class="myselect" style="margin-right:5px">
                    <option value=""></option>
                    @Html.Raw(ViewData["typeOptions"])
                </select>
                <select onclick="appidchange(this.value);" class="myselect" style="width:188px;" id="ApplibraryId" name="ApplibraryId"><option></option></select>
            </td>
        </tr>
        <tr>
            <th>图标：</th>
            <td>
                <input type="text" name="Ico" id="Ico" class="myico" source="" value="@Model.Ico" style="width: 200px" />
                &nbsp;&nbsp;颜色：<input type="text" id="IcoColor" name="IcoColor" value="@Model.IcoColor" class="mytext" style="width:150px" />
            </td>
        </tr>
    </table>
    <div class="buttondiv">
        @if (!Model.Title.IsNullOrWhiteSpace())
        {
            <input type="button" value="添加子项" class="mybutton" onclick="window.location='Body?parentid=@Model.Id&appid=@ViewData["appId"]&tabid=@ViewData["tabId"]';" />
        }
        <input type="button" value="&nbsp;保&nbsp;&nbsp;存&nbsp;" class="mybutton" onclick="saveMenu(this);" />
        @if (Model.Title.IsNullOrWhiteSpace())
        {
            <input type="button" value="&nbsp;返&nbsp;&nbsp;回&nbsp;" class="mybutton" onclick="window.location='Body?menuid=@Model.ParentId&appid=@ViewData["appId"]&tabid=@ViewData["tabId"]';" />
        }
        @if (!Model.Title.IsNullOrWhiteSpace())
        {
            <input type="button" value="&nbsp;删&nbsp;&nbsp;除&nbsp;" class="mybutton" onclick="deleteMenu(this);" />
            <input type="button" value="&nbsp;排&nbsp;&nbsp;序&nbsp;" class="mybutton" onclick="sortMenu();" />
        }
        </div>
</form>
<script type="text/javascript">
    $(function () {
        loadApp($("#Type").val());
        $("#IcoColor").bigColorpicker();
    });
    function appidchange(value) {
        var options = $("#ApplibraryId option");
        for (var i = 0; i < options.length; i++) {
            if (value && options.eq(i).val() == value) {
                $("#Title").val(options.eq(i).text());
            }
        }
    }
    function saveMenu(but) {
        var f = document.forms[0];
        if (new RoadUI.Validate().validateForm(f)) {
            var o = RoadUI.Core.serializeForm($(f));
            $(but).prop("disabled", true);
            $.ajax({
                url: "Save@(Html.Raw(ViewData["queryString"]))", data: o, type: "post", success: function (text) {
                    alert(text);
                    $(but).prop("disabled", false);
                    parent.frames[0].reLoad('@Model.ParentId');
                    window.location = "body?menuid=@Model.Id&appid=@ViewData["appId"]&tabid=@ViewData["tabId"]";
                }
            });
        }
    }
    function loadApp(value) {
        if (!value) {
            return false;
        }
        $.ajax({
            url: "../Applibrary/GetOptionsByAppType?appid=@ViewData["appId"]", type: "post", data: { "type": value, "value": "@Model.AppLibraryId" }, dataType: "text", async: false, cache: false, success: function (txt) {
                var $appid = $("#ApplibraryId");
                $("option", $appid).remove();
                $appid.append('<option value=""></option>' + txt);
            }
        });
    }
    function sortMenu() {
        window.location = "Sort?menuid=@Model.Id&parentid=@Model.ParentId&appid=@ViewData["appId"]&tabid=@ViewData["tabId"]";
    }
    function deleteMenu(but) {
        if (confirm('真的要删除菜单吗?')) {
            $(but).prop("disabled", true);
            $.ajax({
                url: "Delete@(Html.Raw(ViewData["queryString"]))", data: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() }, type: "post", success: function (text) {
                    if (RoadUI.Core.checkLogin(text, false)) {
                        alert(text);
                    }
                    $(but).prop("disabled", false);
                    parent.frames[0].reLoad('@Model.ParentId');
                    window.location = "body?menuid=@Model.ParentId&appid=@ViewData["appId"]&tabid=@ViewData["tabId"]";
                }
            });
        }
    }
</script>